package interview.dfs;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * 根据子节点情况计算根节点值 https://codefun2000.com/p/P1141
 */
public class ColorTree {


    static List<List<Integer>> nodeList = new ArrayList<>();
    static int[] colors;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for (int i = 0;i <= n;i++) {
            nodeList.add(new ArrayList<>());
        }
        for (int i = 2;i <= n;i++) {
            int parent = sc.nextInt();
            nodeList.get(parent).add(i);
        }
        colors = new int[n+1];
        for (int i = 1;i <= n;i++) {
            colors[i] = sc.nextInt();
        }
        System.out.println(dfs(1));
    }

    /**
     * 根据规则计算出的根节点的值
     */
    public static int dfs(int root) {
        List<Integer> childs = nodeList.get(root);
        if (childs.size() == 0) return 1;
        if (childs.size() == 1) return dfs(childs.get(0));
        if (colors[root] == 1)//红色加，绿色异或
            return dfs(childs.get(0)) + dfs(childs.get(1));
        else return dfs(childs.get(0)) ^ dfs(childs.get(1));
    }
}
